//
//  GlobalTools.swift
//  CosClub
//
//  Created by 沙睿 on 2020/4/22.
//  Copyright © 2020 ios. All rights reserved.
//

import UIKit

public protocol AppDelegateWindow {
    var window :UIWindow? {get}
}

public class GlobalTools: NSObject {
    public static func getWindow() -> UIWindow? {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first?.delegate as! AppDelegateWindow
            return scene.window
        }else {
            let scene = UIApplication.shared.delegate as! AppDelegateWindow
            return scene.window
        }
    }
    
    public static func setLocation(key:String, value:Any?) {
        let userD = UserDefaults.standard
        userD.set(value, forKey: key)
    }
    
    public static func getLocation(key:String) -> Any?{
        return UserDefaults.standard.object(forKey:key)
    }
}


public class LoginInformation {
    public static let shared = LoginInformation()
    public var token: String? = "" {
        didSet {
            GlobalTools.setLocation(key: "token", value: self.token)
        }
    }
    public var userId: Int? = 0 {
        didSet {
            GlobalTools.setLocation(key: "userId", value: self.userId)
        }
    }
}


public func Log<T>(_ message:T, file:String = #file, funcName:String = #function, lineNum:Int = #line) {

 #if DEBUG

       let fileName = (file as NSString).lastPathComponent;

      print("打印内容:\n[\(fileName)]:[\(lineNum)]:[\(message)]\n");

 #endif

}
